package com.space;

import com.badlogic.gdx.audio.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;


public class ScrollScene extends Sprite  {
	Texture  _spriteTexture;
	static  int SCREEN_WIDTH = 0;
	private float _background_x;
	private float _background_speed = 0f;
	private TextureRegion tr;
    private Music music;
    
	public ScrollScene(String textureFile, int ScreenWidth, int ScreenHeight, float SceneSpeed)
	{
		_spriteTexture = new Texture(Gdx.files.internal(textureFile));
	  	tr = new TextureRegion(_spriteTexture);
	  	SCREEN_WIDTH = ScreenWidth;
	   _background_speed = SceneSpeed;
	}
    public Music setSceneMusic(String musicFile, boolean setLooping, float volume) {
    
	    music = Gdx.audio.newMusic(Gdx.files.internal(musicFile));
	    music.setLooping(setLooping);
	    music.setVolume(volume);
	    return music;
	     
	}
	    
    public void renderScene(SpriteBatch _batch) {
		
	if(_background_x < - SCREEN_WIDTH )
		    {
		    	_background_x = 0;
		    }
		    
		    _background_x -= Gdx.graphics.getDeltaTime() * _background_speed;
		    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		    _batch.draw(tr, (int)_background_x , 0);
		    _batch.draw(tr, (int)_background_x + SCREEN_WIDTH , 0);
		    _batch.end();
		}
}
